### Example Setup Code Block Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/style-guide/template-reference.md Illustrates how to include optional setup code within examples, such as creating tables. This helps users prepare their environment before running the main examples. ```markdown # Provide optional setup examples # such as creating a table ``` -------------------------------- ### Grafana Installation Link Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-hyperlinks.md Provides an example of rewriting content to improve a hyperlink for installing Grafana, making the call to action clearer. ```markdown Original: > For the best experience, [install](https://grafana.com/grafana/download) Grafana version 7 using the binary, not brew. The plugin requires version 7 or greater, but version 7 works best. For convenience, here are the commands for mac. For other platforms, check the link. | > >## Before you begin
> >Rewritten content: > >## Before you begin > * [Install Grafana version 7](https://grafana.com/grafana/download) using the installer binary **not** brew ``` -------------------------------- ### Example Commands for Prerequisites (Shell) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/faq/faq-before-begin.md Illustrates essential commands that a user might need to have installed or configured before running FeatureBase. This includes examples like 'curl' and 'wget', highlighting the need for them to be in the system's PATH or for the user to be in the correct directory. ```shell You can't run FeatureBase commands in a Terminal unless you've added `/featurebase` to the PATH variable OR are in the correct directory You can't run `curl`, `wget` or `make` commands if they're not installed ``` -------------------------------- ### Verify WSL2 Installation and Docker Setup Commands Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/local-build/local-build-with-WSL2.md Commands to verify WSL2 installation, install Docker within WSL, and configure user permissions to run Docker without sudo. These steps are crucial for the initial setup. ```shell wsl -l -v ``` ```shell curl https://get.docker.com/ | bash ``` ```shell usermod -aG docker ``` ```shell wsl -t ubuntu ``` -------------------------------- ### CREATE TABLE Examples Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-table-create.md Various examples demonstrating how to create tables with different column definitions, data types, and constraints in FeatureBase SQL. ```sql -- Example: CREATE TABLE with string data type CREATE TABLE example_table ( _id STRING, name STRING ); ``` ```sql -- Example: CREATE TABLE with integer constraints CREATE TABLE integer_constraints ( _id ID, count INT ); ``` ```sql -- Example: CREATE TABLE with STRINGSET data type CREATE TABLE stringset_table ( _id ID, tags STRINGSET ); ``` ```sql -- Example: CREATE TABLE with TIMEQUANTUM constraints CREATE TABLE timequantum_table ( _id ID, timestamp TIMESTAMP ); ``` ```sql -- Example: CREATE TABLE with VECTOR data type column CREATE TABLE vector_table ( _id ID, vector ARRAY ); ``` ```sql -- Example: CREATE TABLE with all column types CREATE TABLE all_types_table ( _id STRING, count INT, timestamp TIMESTAMP, tags STRINGSET, vector ARRAY ); ``` -------------------------------- ### Create Table SQL Examples for FeatureBase Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/examples/sql-eg-home.md Examples demonstrating how to create tables in FeatureBase using SQL. ```sql CREATE TABLE IF NOT EXISTS ( "id" BIGINT, "name" VARCHAR(255) ); ``` -------------------------------- ### Build and Install FeatureBase Python Client Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/python-client-library/python-client-install.md Builds and installs the FeatureBase Python client library after cloning the repository. This involves navigating to the cloned directory and running the 'make' command. ```bash cd python-featurebase make ``` -------------------------------- ### Select Data SQL Examples for FeatureBase Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/examples/sql-eg-home.md Examples illustrating how to query and retrieve data from FeatureBase tables using SQL. ```sql SELECT * FROM "users" WHERE "id" > 1; ``` -------------------------------- ### Install fbsql using make Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql/fbsql-install.md Executes the make command to install the fbsql CLI tool after cloning the FeatureBase repository. This command is typically run from within the FeatureBase source code directory. Requires make to be installed. ```shell make install-fbsql ``` -------------------------------- ### Example: Show Columns for 'skills' Table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-columns-show.md An example demonstrating how to use the SHOW COLUMNS statement to inspect the schema of the 'skills' table, showing its columns and their properties. ```sql SHOW COLUMNS FROM skills; ``` -------------------------------- ### CREATE TABLE tuple-set-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Example for creating a 'tuple-set-target' table which includes IDSET, IDSETQ, INT, STRING, STRINGSET, and STRINGSETQ data types. ```sql CREATE TABLE tuple-set-target ( id_set IDSET, id_set_q IDSETQ, value INT, label STRING, string_set STRINGSET, string_set_q STRINGSETQ ); ``` -------------------------------- ### Install Dependencies with Bundler Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/local-build/local-build-with-vm.md This command installs all project dependencies as defined in the Gemfile using Bundler. It's a crucial step after setting up the Ruby environment. ```shell username@virtualmachine $ bundle ``` -------------------------------- ### Insert Data SQL Examples for FeatureBase Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/examples/sql-eg-home.md Examples showcasing how to insert data into FeatureBase tables using SQL. ```sql INSERT INTO "users" ("id", "name") VALUES (1, 'Alice'), (2, 'Bob'); ``` -------------------------------- ### Execute SQL Queries with FeatureBase Python Client Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/python-client-library/python-client-example.md Demonstrates how to connect to FeatureBase Cloud, create a table, insert data using SQL statements, and query the data. It includes examples of DROP TABLE, CREATE TABLE, INSERT INTO, and SELECT statements. ```python # import the library import featurebase # FeatureBase Cloud client print("Connecting to FeatureBase Cloud...") client = featurebase.client( hostport = "https://query.featurebase.com/v2/", database = "", # Replace with your own database id apikey = "") # Replace with your API key # DROP demo table print ("Dropping table if it exists") result=client.query(sql="DROP TABLE python-demo") # Remove `_c` prefix to run against Community # CREATE demo table print ("Single CREATE TABLE python-demo statement") result=client.query(sql="CREATE TABLE python-demo(_id ID, intcol INT, stringcol STRING, idsetcol IDSET)") # Run SQL statements in sequence and stop on error print ("Array of INSERT INTO python-demo statements") sqllist=[] sqllist.append("INSERT INTO python-demo (_id, intcol, stringcol, idsetcol) VALUES (2,234,'row2, stringcolumn',[500,600,700,800])") sqllist.append("INSERT INTO python-demo (_id, intcol, stringcol, idsetcol) VALUES (3,345,'row3, stringcolumn',[900,1000,1100,1200])") # run statements then stop on error results = client.querybatch(sqllist, stoponerror=True) if result.ok: print("Rows affected:",result.rows_affected,"Execution time:",result.execution_time,"ms") print(result.schema) else: print(result.error) # SELECT FROM python-demo print("SELECT statement on python-demo") result=client.query(sql="SELECT _id,SETCONTAINS(idsetcol,700) FROM python-demo") if result.ok: print(result.data) print("Execution time:",result.execution_time,"ms") else: print(result.error) ``` -------------------------------- ### Example INSERT Statement for SET and SETQ Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/data-types/data-type-set-setq.md Demonstrates how to insert data into columns with SET and SETQ data types, including ID and string values, and timestamps for SETQ. ```sql INSERT INTO all-datatypes (_id, idsetcol, idsetqcol, stringsetcol, stringsetqcol) VALUES (1, [10,20,30], {1709706283,[90,80,70]}, ['ten', 'twenty', 'thirty'], {'2024-03-06T06:24:43.261Z',['ninety','eighty','seventy']}); ``` -------------------------------- ### Clone FeatureBase repository with Git Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql/fbsql-install.md Clones the FeatureBase GitHub repository to your local machine. This is the first step in obtaining the fbsql tool. Requires Git to be installed. ```git git clone git@github.com:molecula/featurebase.git ``` -------------------------------- ### SQL CREATE TABLE with DECIMAL data type Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/data-types/data-type-decimal.md Example of creating a SQL table with a DECIMAL data type column, demonstrating its usage. ```sql CREATE TABLE product_sales ( id INT PRIMARY KEY, product_name STRING, price DECIMAL(10, 2) -- Example: 10 total digits, 2 after decimal ); ``` -------------------------------- ### Create PostgreSQL Table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-postgres-source.md This SQL snippet demonstrates how to create a table in PostgreSQL with various data types. ```sql CREATE TABLE postgres_table ( idkey int, intf int, stringf varchar(30), idf int, stringsetf varchar(30), idsetf varchar(30)); ``` -------------------------------- ### Bulk Insert Data SQL Examples for FeatureBase Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/examples/sql-eg-home.md Demonstrates efficient bulk insertion of data into FeatureBase tables using SQL. ```sql INSERT INTO "users" ("id", "name") VALUES (3, 'Charlie'), (4, 'David'); ``` -------------------------------- ### Install FeatureBase Python Client via Pip Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/python-client-library/python-client-install.md Installs the FeatureBase Python client library from the Python Package Index (PyPI) using pip. This is the recommended method for most users to easily add the library to their projects. ```bash pip install featurebase ``` -------------------------------- ### SQL CREATE TABLE with all data types example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/data-types/data-type-id.md This snippet demonstrates the creation of a table with various data types, including the ID numeric datatype. It serves as a comprehensive example for defining table structures in FeatureBase SQL. ```sql CREATE TABLE "my_table" ( "id" ID, "name" STRING, "age" TIMESTAMP ); ``` -------------------------------- ### Highlighting Code in Paragraphs (Go Example) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-rules.md Demonstrates using backticks for inline code highlighting, suitable for flags or arguments in a Go context. ```go The `min` constraint... ``` -------------------------------- ### Run fbsql loader command Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-ingest.md Executes the `fbsql loader` command to ingest data into FeatureBase. It requires a configuration file (e.g., `example-config.toml`) and specifies the data source type. ```bash loader-impala example-config.toml loader-kafka example-config.toml loader-postgres example-config.toml ``` -------------------------------- ### Example Folder Structure for SQL Functions Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/style-guide/content-nav-page-order.md Demonstrates a typical folder structure for organizing SQL function-related Markdown files, using alphabetical naming. ```file-structure functions ├── function-ascii.md ├── function-char.md └── function-len.md ``` -------------------------------- ### CSV Transformation Link Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-hyperlinks.md Shows an example of rewriting content for a hyperlink related to transforming CSV files into FeatureBase Cloud schema syntax. ```markdown Original: > The first step is to transform every row in the CSV file into the FeatureBase Cloud schema syntax, which can be seen in further detail at [here](/cloud/cloud-data-ingestion/streaming-https-endpoint/cloud-streaming-overview). The output of this function will create 1 to many properly formatted JSON files for every 1000 records in your CSV file. Rewritten content >## Step one - transform rows to FeatureBase cloud schema syntax > > Every 1000 records in the CSV file are converted to formatted JSON files which conform to the FeatureBase Cloud Schema Syntax. > > * [Example of CSV conversion](/cloud/cloud-data-ingestion/streaming-https-endpoint/cloud-streaming-overview) ``` -------------------------------- ### CREATE TABLE orc-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Demonstrates creating an 'orc-target' table with BOOL, ID, INT, and STRING data types. Includes options for conditional creation and adding comments. ```sql CREATE TABLE IF NOT EXISTS orc-target WITH COMMENT 'A table for ORC data' ( id ID, count INT, status BOOL, label STRING ); ``` -------------------------------- ### fbsql SET Variable Examples Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql/fbsql-running-sql.md Illustrates different ways to set variables in fbsql, showing how multiple values are handled when separated by commas versus spaces. ```bash set myvarname 1,2,3,4 set myvarname 1 2 3 4 ``` -------------------------------- ### Insert Data into PostgreSQL Table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-postgres-source.md This SQL snippet shows how to insert sample data into the PostgreSQL table created previously. ```sql INSERT INTO postgres_table VALUES (0, 0, 'a', 0, 'a', '3'), (1, 0, 'a', 0, 'c', '4'), (2, 0, 'a', 0, 'd', '5'); ``` -------------------------------- ### INSERT statement with specific columns and values Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-insert.md Demonstrates inserting specific data into the 'services' table, including the '_id', 'servicelist', and 'price' columns. This example shows how to populate a table with a single record. ```sql INSERT INTO services (_id, servicelist, price) VALUES (1, 'free deliveries on orders over $50', 0.00); ``` -------------------------------- ### CREATE TABLE tan-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Example of creating a 'tan-target' table with ID and STRINGSET data types. This table is associated with insert operations. ```sql CREATE TABLE tan-target ( entity_id ID, tags STRINGSET ); ``` -------------------------------- ### BULK INSERT ORC Data from URL Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/examples/sql-eg-insert/sql-eg-insert-bulk-orc-target.md This SQL statement demonstrates how to perform a bulk insert operation into the 'orc-target' table using data from an ORC file located at a specified URL. It includes mapping ORC fields to table columns and setting the input format. ```sql BULK INSERT INTO orc-target( _id, stringcol, boolcol, intcol ) MAP( 0 id, 1 STRING, 2 BOOL, 3 INT ) FROM 'https://sample-files-hh.s3.us-east-2.amazonaws.com/samplefile.orc' WITH FORMAT 'ORC' INPUT 'URL'; ``` -------------------------------- ### Create Table statement with all data types Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/data-types/data-types-home.md This example demonstrates how to create a table using SQL, showcasing the usage of various FeatureBase data types including BOOL, ID, SET, STRING, TIMESTAMP, and VECTOR. ```sql CREATE TABLE "example" ( "id" ID, "name" STRING, "description" VARCHAR(256), "timestamp" TIMESTAMP, "value" DECIMAL(10,2), "enabled" BOOL, "set_field" SET, "vector_field" VECTOR ); ``` -------------------------------- ### External Hyperlink Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-hyperlinks.md Shows how to create an external hyperlink to a URL, including opening the link in a new tab. ```markdown `[meaningful-anchor-text](https://url){:target="_blank"}` `[Visit the FeatureBase website](https://featurebase.com)` ``` -------------------------------- ### Show DDL for 'skills' Table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-table-create-show.md This example demonstrates how to retrieve the CREATE TABLE DDL for the 'skills' table, which is automatically created when a database with sample data is set up. The output shows the table schema including column names and their types. ```sql SHOW CREATE TABLE skills; ``` -------------------------------- ### CREATE TABLE ndjson-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Example for creating an 'ndjson-target' table with BOOL, ID, STRING, and TIMESTAMP data types. Supports options like IF NOT EXISTS and WITH COMMENT. ```sql CREATE TABLE IF NOT EXISTS ndjson-target WITH COMMENT 'A table for NDJSON data' ( is_active BOOL, record_id ID, description STRING, created_at TIMESTAMP ); ``` -------------------------------- ### TOML Configuration for FeatureBase PostgreSQL Loader Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-postgres-source.md This TOML configuration file specifies the settings for the FeatureBase loader to connect to and ingest data from PostgreSQL. ```toml table = "loader-target" query = "select idkey, intf, stringf, idf, stringsetf, idsetf from postgres_table;" driver = "postgres" connection-string = "postgres://:@localhost:5432/mydatabase?sslmode=disable" batch-size = 1 ``` -------------------------------- ### CHARINDEX() with Starting Position SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-charindex.md Illustrates how to use the CHARINDEX() function with an optional starting position argument to search for a substring from a specific point in the input string. Includes table setup and a SELECT query. ```sql create table customers (_id id, segment string); insert into customers(_id,segment) values (1,'this is great') select _id, charindex('is',segment,3) as charindex from customers; ``` -------------------------------- ### CREATE TABLE csv-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Example of creating a table named 'csv-target' using INT and STRING data types. This table structure is suitable for bulk insert operations. ```sql CREATE TABLE csv-target ( id INT, name STRING ); ``` -------------------------------- ### Connect to FeatureBase Cloud Database Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-ingest.md Connects to your FeatureBase Cloud database using either user credentials or an API key. This is a prerequisite for running subsequent commands. ```bash fbsql connect --host --user --password fbsql connect --host --api-key ``` -------------------------------- ### Select All from myspecies Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/examples/sql-eg-select/sql-eg-select-from-myspecies.md Retrieves all columns and rows from the myspecies table to verify data insertion. ```sql SELECT * from myspecies; ``` -------------------------------- ### ASCII() Function Example: Get ASCII value from a column Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-ascii.md Illustrates how to use the ASCII() function to retrieve the ASCII value of a string stored in a table column. This example includes table creation, data insertion, and a SELECT statement to display the results. ```sql create table segments (_id id, segment string); insert into segments(_id, segment) values (1,'r') select _id, ascii(segment) as segment from segments; +-----+----------+ | _id | segment | +-----+----------+ | 1 | 114 | +-----+----------+ ``` -------------------------------- ### Create VIEW for Customer Data Access Control (SQL) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-view-create.md This example demonstrates creating a 'customer' view that exposes only specific, shareable data from the 'person' table. It includes table creation, data insertion, view definition, and a query to show the view's contents. ```sql create table person (_id id, dob timestamp, ssn string, name string); insert into person(_id, dob, ssn, name) values (1, '1950-01-01T00:00:00Z', '123456789', 'John Doe 1'); insert into person(_id, dob, ssn, name) values (2, '1960-01-01T00:00:00Z', '123456780', 'John Doe 2'); insert into person(_id, dob, ssn, name) values (3, '1970-01-01T00:00:00Z', '123456700', 'John Doe 3'); insert into person(_id, dob, ssn, name) values (4, '2080-01-01T00:00:00Z', '123456000', 'John Doe 4'); create view customer as select _id, name, datetimepart('yy',dob) birth_year from person; select * from customer order by birth_year; ``` -------------------------------- ### CREATE TABLE cosvec-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Example of creating a table named 'cosvec-target' with ID, STRING, and VECTOR data types. This is often related to insert operations into the same table. ```sql CREATE TABLE cosvec-target ( id ID, name STRING, vector VECTOR ); ``` -------------------------------- ### Build and Serve Documentation with Docker Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/local-build/local-build-with-WSL2.md Steps to build the Docker image for the documentation and serve the Jekyll site using Docker Compose. Assumes Docker Desktop is running and you are in the project directory. ```shell docker build - < Dockerfile ``` ```shell docker compose up serve ``` -------------------------------- ### SQL: Get Day of Week from Date Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimepart.md Illustrates using the DATETIMEPART() function to determine the day of the week for a given timestamp, where Sunday is represented as 0. The example covers table setup and the query execution. ```sql create table demo (_id id, ts timestamp timeunit 's'); insert into demo(_id, ts) values (1, '1970-01-01T00:00:00Z'); select _id, datetimepart('w',ts) from demo; ``` -------------------------------- ### SQL: Create and Insert data into Colors table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-offset.md Demonstrates creating a 'colors' table and inserting sample data, which is used in subsequent OFFSET() query examples. ```sql create table colors (_id id, color string); insert into colors(_id,color) values (1,'green') insert into colors(_id,color) values (2,'red') insert into colors(_id,color) values (3,'yellow') insert into colors(_id,color) values (4,'blue') insert into colors(_id,color) values (5,'orange') ``` -------------------------------- ### Create VIEW for Retiree Logic (SQL) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-view-create.md An example of creating a 'retiree' view that identifies individuals eligible for retirement based on their date of birth. It includes table creation, data insertion, view creation, and a query to display the results. ```sql create table person (_id id, dob timestamp); insert into person(_id, dob) values (1, '1950-01-01T00:00:00Z'); insert into person(_id, dob) values (2, '1960-01-01T00:00:00Z'); insert into person(_id, dob) values (3, '1970-01-01T00:00:00Z'); insert into person(_id, dob) values (4, '2080-01-01T00:00:00Z'); create view retiree as select _id, datetimeadd('yy',62,dob) retirement_dt from person where datetimeadd('yy',62,dob)>current_timestamp; select * from retiree order by retirement_dt; ``` -------------------------------- ### Use LEN() on a column - SQL Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-len.md Demonstrates how to use the LEN() function to get the length of a string stored in a column. This example creates a table, inserts data, and then selects the ID and the length of the 'segment' column. ```sql create table segments (_id id, segment string); insert into segments(_id, segment) values (1,'testing') select _id, len(segment) as length from segments; +-----+----------+ | _id | length | +-----+----------+ | 1 | 7 | +-----+----------+ ``` -------------------------------- ### CREATE TABLE parquet-target SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-table-create-statements.md Example of creating a 'parquet-target' table using ID, INT, and DECIMAL data types. This table structure is often used with bulk insert operations. ```sql CREATE TABLE parquet-target ( item_id ID, quantity INT, price DECIMAL(10, 2) ); ``` -------------------------------- ### fbsql Run Query and Verify Output File Content Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql/fbsql-config-output.md This example executes a `select` query and then uses `\! cat` to display the content of the output file, showing both the comment and the query results. ```bash select * from products; \! cat output-test.sql Testing 1,2,3 _id | item | price | stock -----+----------------------+--------+------- 1 | pen | 2.50 | NULL 2 | pencil | 0.50 | NULL 3 | playpen | 52.50 | NULL 4 | gold-plated earplugs | 122.50 | NULL (0 rows) ``` -------------------------------- ### DATETIMENAME() - Get Day of Week Name Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimename.md Illustrates the usage of the DATETIMENAME() function to obtain the name of the day of the week for a specific date. This example includes table creation, data insertion, and a query to extract the weekday name. ```sql create table demo (_id id, ts timestamp timeunit 's'); insert into demo(_id, ts) values (1, '1970-01-01T00:00:00Z'); select _id, datetimename('w',ts) from demo; ``` -------------------------------- ### Handle NULL input parameters with DATETIMEDIFF() Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimediff.md Demonstrates how the DATETIMEDIFF() function handles `null` input parameters. If any argument is `null`, the function returns `NULL`. This example shows table setup, data insertion, and a query with a `null` timeunit. ```sql create table demo (_id id, start-date timestamp timeunit 's', end-date timestamp timeunit 's'); insert into demo(_id, start-date, end-date) values (1, '2023-02-27T21:30:00Z', '2023-03-01T21:30:00Z'); select _id, datetimediff(null, start-date, end-date) as diff from demo; _id | diff -----+------ ``` -------------------------------- ### Real-World Syntax Application Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/style-guide/template-reference.md Shows how to present a real-world application of the documented syntax. This section should include a brief explanation of the code block's purpose and its practical use. ```markdown # real world application of syntax ``` -------------------------------- ### Install ebnf2railroad via npm Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/regenerate-sql-svg/README.md Installs the ebnf2railroad package globally using npm, which is required for generating BNF diagrams. ```shell sudo npm install -g ebnf2railroad ``` -------------------------------- ### Calculate days difference between two dates using DATETIMEDIFF() Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimediff.md Calculates the difference in days between two specific dates. This example demonstrates table creation, data insertion, and querying the date difference. It handles cases where the end date is after the start date. ```sql create table demo (_id id, start-date timestamp timeunit 's', end-date timestamp timeunit 's'); insert into demo(_id, start-date, end-date) values (1, '2023-02-27T21:30:00Z', '2023-03-01T21:30:00Z'); select _id, datetimediff('d', start-date, end-date) as days_diff from demo; _id | days_diff -----+----------- ``` -------------------------------- ### Internal Hyperlink Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-hyperlinks.md Demonstrates the structure for creating an internal hyperlink to a specific document within the FeatureBase documentation. ```markdown `[meaningful-anchor-text](/docs/folder/filename)` `[Learn how to create tables in FeatureBase cloud](/docs/cloud/cloud-tables/cloud-table-create)` ``` -------------------------------- ### Success Callout Implementation Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-content-callouts.md Provides examples of creating 'success' callouts using HTML and Markdown. This callout type is for infrequent use but available when needed. ```html

Q'PLA! This is a success callout with a joke because it's that time of the day.

``` ```markdown {: .success } Q'PLA! This is a success callout with a joke because it's that time of the day. ``` -------------------------------- ### COALESCE() SQL Function Examples Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-coalesce.md Demonstrates the usage of the COALESCE() function in FeatureBase SQL to replace NULL values with specified defaults. Includes examples for handling single null columns, multiple null columns, and numeric null values. ```SQL CREATE TABLE stock (__id ID, product STRING, brand STRING, subcategory STRING, category STRING, family STRING, quantity_available INT, minimum_to_have INT); INSERT INTO stock VALUES (1, 'pork ribs', NULL, 'pork meat', 'meat','food',400, 130), (2, 'tomatoes','Mr Red', NULL, 'vegetables','food',280, 100), (3,'lettuce',NULL, 'Leaf vegetables', NULL,'food',280, Null), (4,'Bananas',NULL, NULL,NULL,'food',Null, NULL), (5,'hamburger','MaxBurg','cow meat','meat','food',220, 150), (6,'hamburger','SuperBurga',Null,Null,Null,125, Null); SELECT * FROM stock; SELECT product, COALESCE(brand, 'locally grown') AS final_brand FROM stock; SELECT product, COALESCE(subcategory, category, family, 'no product description') AS product_and_subcategory FROM stock; SELECT _id, COALESCE(quantity_available, minimum_to_have, 100) AS quantity FROM stock; ``` -------------------------------- ### Create a Sample Cloud Database Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/cloud/cloud-databases/cloud-db-manage.md Learn how to create a sample database in FeatureBase Cloud. This is a summary of the process. ```APIDOC ## Learn how to create a sample database ### Description This section provides instructions on creating a sample database within the FeatureBase Cloud environment. ### Method GET ### Endpoint /docs/cloud/cloud-databases/cloud-db-create-sample ``` -------------------------------- ### DATE_TRUNC() SQL Example: Display Date, Time with Hours and Minutes Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-date_trunc.md Shows how to use DATE_TRUNC() to display the date and time, including hours and minutes, but excluding seconds. The example creates a table, inserts data, and uses DATE_TRUNC('mi', ts). ```sql create table demo (_id id, ts timestamp timeunit 's'); insert into demo(_id, ts) values (1, '1970-01-01T00:00:00Z'); select _id, date_trunc('mi',ts) from demo; ``` -------------------------------- ### ASCII() Function Syntax Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-ascii.md Demonstrates the basic syntax for using the ASCII() function in FeatureBase SQL. ```sql ascii(expr) ``` -------------------------------- ### Calculate hours difference when end time is before start time using DATETIMEDIFF() Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimediff.md Calculates the difference in hours between two datetime values, demonstrating a scenario where the end time precedes the start time, resulting in a negative difference. It includes table creation and data insertion. ```sql create table demo (_id id, start-date timestamp timeunit 's', end-date timestamp timeunit 's'); insert into demo(_id, start-date, end-date) values (1, '2023-03-01T12:00:00Z', '2023-03-01T09:00:00Z'); select _id, datetimediff('h', start-date, end-date) as hours_diff from demo; _id | hours_diff -----+------------ ``` -------------------------------- ### SQL: Extract Substring from Column Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-substring.md Extracts a substring from the 'segment' column of the 'segments' table, starting at index 0 with a length of 3 characters. ```SQL create table segments (_id id, segment string); insert into segments(_id,segment) values (1,'green') select _id, substring(segment,0,3) as substr from segments; +-----+----------+ | _id | substr | +-----+----------+ | 1 | gre | +-----+----------+ ``` -------------------------------- ### Page Title Example - Markdown Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/style-guide/custom-heading-page-title.md This snippet demonstrates the standard format for a page title using Markdown. It's typically the first heading on a documentation page. ```markdown # How do I write FeatureBase Docs? ``` -------------------------------- ### SQL: Extract Substring from Reversed String Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-substring.md Extracts a substring from a reversed string in the 'segment' column, starting at index 1. The REVERSE() function is used first. ```SQL create table segments (_id id, segment string); insert into segments(_id,segment) values (1,'red') select _id, substring(reverse(segment), 1) as substr from segments; +-----+----------+ | _id | substr | +-----+----------+ | 1 | er | +-----+----------+ ``` -------------------------------- ### Rewritten Single Word Hyperlink Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-hyperlinks.md Illustrates how to improve content by replacing single-word hyperlinks with more descriptive text and structuring the information better. ```markdown Original: >Everything that can be done in the user interface can be accomplished via REST api calls. Furthermore, APIs allow you to perform additional actions as well as gather more metadata about your organization and data. You will likely interact with the APIs in a production setting. Full Documentation for the APIs can be found [here](/cloud/cloud-api). Rewritten as: >REST API calls will tend to be used in production environments: > * instead of the FeatureBase user interface > * to gather more metadata about your organization and data > > ## Further information > > * [Full API documentation](/cloud/cloud-api) ``` -------------------------------- ### Show Columns Syntax Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-columns-show.md The basic syntax for the SHOW COLUMNS statement, used to display the schema of a specified table. ```sql SHOW COLUMNS FROM table_name; ``` -------------------------------- ### FeatureBase TopK Query Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/cloud/cloud-query/cloud-query-sample-db.md A simple FeatureBase TopK query to find the top 5 most frequent 'hobbies' in the 'cseg' table. ```featurebase [cseg]TopK(hobbies, k=5) ``` -------------------------------- ### Testing Set Membership as a Where Clause Filter Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-set.md Example of using a SET function (SETEXCLUDES) in the WHERE clause to filter rows where a specific value is not present in the set column. ```sql SELECT _id FROM segments WHERE SETEXCLUDES(segment, 'purple'); ``` -------------------------------- ### Create Impala Source Table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-impala-source.md SQL statement to create a sample table in an Impala database. This table structure is used as the source for data import into FeatureBase. ```sql CREATE TABLE testdb.impala_table ( idkey int, intf int, stringf string, idf int, stringsetf string, idsetf string); ``` -------------------------------- ### SQL: Extract suffix from string column Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-suffix.md This example demonstrates how to use the SUFFIX() function to extract a specified number of characters from the end of a string stored in a database column. ```sql create table segments (_id id, segment string); insert into segments(_id,segment) values (1,'FOOBAR') select _id, suffix(segment, 3) as convertedstr from segments; +-----+---------------+ | _id | convertedstr | +-----+---------------+ | 1 | BAR | +-----+---------------+ ``` -------------------------------- ### Serve Jekyll Site Locally Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/local-build/local-build-with-vm.md This command serves the Jekyll site locally, allowing developers to preview changes in real-time. A restart is required for changes in `_config.yml`. ```shell bundle exec jekyll serve ``` -------------------------------- ### FeatureBase SQL DATETIMEADD() - Calculate Past Date Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimeadd.md This example shows how to use a negative time duration with DATETIMEADD() to calculate a date 100 days prior to the current date. ```sql select datetimeadd('d', -100, current_date) as hundred_days_ago_today; ``` -------------------------------- ### BULK INSERT ORC Data (SQL) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/_includes/sql-guide/sql-eg-insert-bulk-statements.md Inserts data from an ORC file into a FeatureBase table. Configuration options include format and input source. ```sql BULK INSERT orc-target FROM 'URL_TO_ORC' WITH ( FORMAT = 'ORC', INPUT = 'URL' ); ``` -------------------------------- ### Connect to FeatureBase using psql CLI Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-procedures.md This snippet shows how to connect to a FeatureBase instance using the psql command-line interface. It assumes FeatureBase is running on localhost with a specific port. ```shell psql -h localhost -p 55432 ``` -------------------------------- ### INSERT statement with STRINGSET data types Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-insert.md This example demonstrates inserting multiple string values into a STRINGSET column in the 'myspecies' table. It shows how to provide a list of strings for a single '_id'. ```sql INSERT into myspecies (_id, species) values ('yes', ['Manatee', 'Sea Horse', 'Koala']), ('no', ['Starfish']); ``` -------------------------------- ### INSERT statement overwriting existing values Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-insert.md This example illustrates how the INSERT statement overwrites existing data when a record with a duplicate '_id' is encountered in the 'services' table. This is useful for updating records. ```sql INSERT INTO services (_id, servicelist, price) VALUES (2, 'local postage per item', 2.20); ``` -------------------------------- ### SQL EXPLAIN Example: CREATE TABLE Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-explain.md Demonstrates how to use the EXPLAIN statement with a CREATE TABLE query. It shows the SQL command and the resulting JSON output which represents the execution plan for creating the 'doctest' table. ```sql EXPLAIN CREATE TABLE doctest (_id ID, stringcol STRING); ``` ```json { "_op": "*planner.PlanOpQuery", "_schema": [], "child": { "_op": "*planner.PlanOpCreateTable", "ifNotExists": false, "tableName": "doctest" }, "sql": "EXPLAIN CREATE TABLE doctest (_id ID, stringcol STRING);", "warnings": [] } ``` -------------------------------- ### Basic INSERT statement Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/statements/statement-insert.md This snippet shows the fundamental syntax for the INSERT statement, specifying the target table, optional column list, and the corresponding value list. ```sql INSERT INTO [()] VALUES {(),...}; ``` -------------------------------- ### SET and SETQ Syntax Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/data-types/data-type-set-setq.md Defines the general syntax for the SET and SETQ data types, including optional TIMEQUANTUM and TTL constraints for SETQ. ```sql {ID | STRING}SET{Q TIMEQUANTUM '' [TTL '']} ``` -------------------------------- ### Insert Data into Impala Source Table Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql-examples/fbsql-loader-eg-impala-source.md SQL statement to insert sample data into the Impala source table. This data will be imported into FeatureBase. ```sql INSERT INTO testdb.impala_table VALUES (0, 0, 'a', 0, 'a', '3'), (1, 0, 'a', 0, 'c', '4'), (2, 0, 'a', 0, 'd', '5'); ``` -------------------------------- ### Testing Set Membership with Multiple Conditions Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-set.md Example demonstrating the use of multiple SETEXCLUDES functions combined with an AND operator in the WHERE clause to filter rows based on multiple set membership criteria. ```sql SELECT _id FROM segments WHERE SETEXCLUDES(segment, 'purple') AND SETEXCLUDES(segment, 'yellow'); ``` -------------------------------- ### Testing Set Membership in Select List Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-set.md Example of using a SET function (SETEXCLUDES) within the SELECT list to test if a value is not present in a set column. Returns a boolean result. ```sql SELECT SETEXCLUDES(segment, 'purple') AS NOTPURPLE FROM segments; ``` -------------------------------- ### Download FeatureBase Python Client via Git Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/python-client-library/python-client-install.md Clones the FeatureBase Python client library repository from GitHub using Git. This method is useful for developers who want to access the source code directly. ```bash git clone git@github.com:FeatureBaseDB/python-featurebase.git ``` -------------------------------- ### DATETIMENAME() - Get Month Name Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-datetimename.md Demonstrates how to use the DATETIMENAME() function to retrieve the name of the month from a given timestamp. It involves creating a table, inserting a sample timestamp, and then querying the month name. ```sql create table demo (_id id, ts timestamp timeunit 's'); insert into demo(_id, ts) values (1, '1970-01-01T00:00:00Z'); select _id, datetimename('m',ts) from demo; ``` -------------------------------- ### CHARINDEX() SQL Example Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-charindex.md Demonstrates the basic usage of the CHARINDEX() function to find the starting position of a substring within a string. It includes table creation, data insertion, and a SELECT statement to retrieve the position. ```sql create table customers (_id id, segment string); insert into customers(_id,segment) values (1,'this is great') select _id, charindex('is',segment) as charindex from customers; ``` -------------------------------- ### Code Blocks with Language Specification (Go) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/writing-help/writing-rules.md Shows how to use triple backticks to create code blocks, specifying the programming language (Go) for syntax highlighting. ```go ```go ``` -------------------------------- ### fbsql CLI Syntax for Output Flags Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql/fbsql-config-output.md Displays the general syntax for fbsql output-related commands, including meta-prefix options and commands like cd, out, qecho, and warn. ```bash () [--history-path=""] | [cd []] | [[o | out] ] | [qecho ] | [warn ] ] ``` -------------------------------- ### DATE_TRUNC() SQL Example: Display Year and Month Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-date_trunc.md Demonstrates how to use the DATE_TRUNC() function to display only the year and month from a timestamp. It involves creating a table, inserting data, and querying with DATE_TRUNC('m', ts). ```sql create table demo (_id id, ts timestamp timeunit 's'); insert into demo(_id, ts) values (1, '1970-01-01T00:00:00Z'); select _id, date_trunc('m',ts) from demo; ``` -------------------------------- ### fbsql CLI Syntax Overview Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/tools/fbsql/fbsql-running-sql.md This snippet outlines the general syntax for interacting with the fbsql command-line interface, including meta-flags for connection, schema inspection, variable management, and query execution. ```bash [ () [ c|connect [ | - ] ] | [ d[< tablename>|t|v ] ] | [ l|list ] | [ set [variable-value,...] ] | [ unset ] | [ i|include ] | [ watch ] | [ t|timing [on|off] ] | [ p|print ] | [ r|reset ] | ] ``` -------------------------------- ### Serve Docker Container Source: https://github.com/featurebasedb/featurebase-docs/blob/main/help-on-help/local-build/local-build-with-docker.md Serves the Docker container to view the local site. Changes to configuration files like `/_config.yml` are not loaded automatically while the site is running. Run this command in the `/featurebase-docs` directory. ```bash docker compose up serve ``` -------------------------------- ### Use TOTIMESTAMP() in SELECT Query with Filtering (SQL) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-totimestamp.md This example demonstrates using the TOTIMESTAMP() function within a SELECT query to convert an integer column to a timestamp and then filtering the results based on this converted timestamp. ```sql create table demo (_id id, int_ts int); insert into demo(_id, int_ts) values (1, 86400); insert into demo(_id, int_ts) values (2, 86400); insert into demo(_id, int_ts) values (3, 86400000); select _id, int_ts, TOTIMESTAMP(int_ts, 's') as ts from demo; select _id, int_ts, TOTIMESTAMP(int_ts, 's') as ts from demo where TOTIMESTAMP(int_ts, 's')>'1970-01-02T00:00:00Z'; ``` -------------------------------- ### Convert Granular Integers to Timestamp with TOTIMESTAMP() (SQL) Source: https://github.com/featurebasedb/featurebase-docs/blob/main/docs/sql-guide/functions/function-totimestamp.md This example shows how to use the TOTIMESTAMP() function with different time units ('s', 'ms', 'us', 'ns') to convert integer values with varying granularities into timestamps. ```sql create table demo (_id id, ts timestamp timeunit 's'); insert into demo(_id, ts) values (1, TOTIMESTAMP(90061)); insert into demo(_id, ts) values (2, TOTIMESTAMP(90061, 's')); insert into demo(_id, ts) values (3, TOTIMESTAMP(90061000,'ms')); insert into demo(_id, ts) values (4, TOTIMESTAMP(90061000000,'us')); insert into demo(_id, ts) values (5, TOTIMESTAMP(90061000000000,'ns')); select _id, ts from demo; ```