How to exec against a loaded splayed table in KDB? - kdb

I have a splayed table written to disk via .Q.dpft[]. After load this table using the \l system command, I can select from this table, e.g., select column_name from splayed_table where xyz
However, when I convert select to exec, I always get the 'nyi error: Not yet implemented. As a workaround, I use: first value flip instead of exec
I am doing something wrong?
Is there a better way?
Note: My KDB+ is KDB+ 3.3 2016.03.14 (Linux 64-bit).

exec cannot be used against a splayed table. A more efficient workaround may be to do exec column_name from select column_name from splayed_table

Related

How to add ONE column to ALL tables in postgresql schema

question is pretty simple, but can't seem to find a concrete answer anywhere.
I need to update all tables inside my postgresql schema to include a timestamp column with default NOW(). I'm wondering how I can do this via a query instead of having to go to each individual table. There are several hundred tables in the schema and they all just need to have the one column added with the default value.
Any help would be greatly appreciated!
The easy way with psql, run a query to generate the commands, save and run the results
-- Turn off headers:
\t
-- Use SQL to build SQL:
SELECT 'ALTER TABLE public.' || table_name || ' add fecha timestamp not null default now();'
FROM information_schema.tables
WHERE table_type = 'BASE TABLE' AND table_schema='public';
-- If the output looks good, write it to a file and run it:
\g out.tmp
\i out.tmp
-- or if you don't want the temporal file, use gexec to run it:
\gexec

extracting meta info from a table psql using information_schema

How do I extract following meta information from a psql table. column_name, data_type, char_max_length,numeric_precision,constraint_type, constraint_reference, check_clause .In short the information that we have got by this query "\d table_name".
Start psql with the -E flag, and take note of the queries it generates when you issue \d table_name -- you'll need to reproduce many or most of those queries in order to get all the metadata you're asking for.

How can a list of table's field names be queried from PostgreSQL?

How can a plain text list of the field names of table be retrieved from PostgreSQL database?
Just query INFORMATION_SCHEMA.COLUMNS, like this:
SELECT
column_name,
data_type,
character_maximum_length,
ordinal_position
FROM information_schema.columns
WHERE table_name = 'mytable'
Better still, INFORMATION_SCHEMA is almost universally supported by all popular SQL databases, so this should work anywhere.
If you really want just dump plain text file recipe, you can execute this query using command line psql and save it as CSV or something like that.

oracle has 'DESCRIBE' to get all the details of the table like wise does t/sql has any thing

oracle has 'DESCRIBE' to get all the details of the table like wise does t/sql has any thing.
SQL Server has sp_help/sp_helptext
MySQL has describe
Sql-Server's sp_help is about as close as you get for something built-in. Remeber to put the tablename in as a parameter...:-)
EXEC sp_help 'mytable'
If you're in ssms, you can r-click your query window and opt to output results to text -- it's a little easier to read the output.
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/913cd5d4-39a3-4a4b-a926-75ed32878884.htm
Also -- you can write your own using the system tables (sys.objects, sys.columns, ...) I think 'DESCRIBE' just gives you column name, nullable, and type... so not nearly as much as sp_help provides.
SELECT * FROM sysobjects WHERE parent_obj = (SELECT id FROM sysobjects WHERE name = 'table_name') AND xtype='PK'
will show table details.
SELECT * FROM sys.Tables
will list all tables
There is no describe equivalent.
you might find this searching for MSSQL instead of T/SQL. Most people talking about Transact SQL are talking about stored procedures.

How do I find all code, triggers from an oracle database that relate to specific tables?

I have a problem where I need to remove all code and triggers from a database that relate to certain tables in order for a Solaris package to install. Long complicated story but I need
to start with a clean slate.
I've managed to remove all the existing tables/synonyms, but how to locate the code/triggers from sqlplus that is related?
Unfortunately, it's not feasible to drop the database and recreate it.
Well, it turns out all the table names are prefixed with my module name DAP.
So, to find all the table names and public synonyms with sqlplus:
select table_name from all_tables where table_name like 'DAP%';
select synonym_name from all_synonyms where table_name like 'DAP%';
To get a list of triggers and sequences
select trigger_name from all_triggers where table_name like 'DAP%';
select sequence_name from all_sequences where sequence_name like 'DAP%';
To get a list of all the constraints
select table_name, constraint_name from all_constraints where table_name like 'DAP%';
To get the DAP related code:
select text from dba_source where name like 'DAP%';
I can now write a script that drops everything.
You should be able to query the system table ALL_TRIGGERS to find the triggers. It has a table_name column. You can probably find the other related objects with different system tables (been awhile since I've messed with Oracle).
http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2107.htm